package smecta.client.print.controller;


import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import org.springframework.web.bind.annotation.RestController;
import smecta.client.print.domain.SummaryQueryModel;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class SummaryQueryController {

    @FXML
    private TableColumn<SummaryQueryModel, Integer> snCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> produceNameCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> produceSpecCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> batchNumCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> gradeCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> sizeCol;
    @FXML
    private TableColumn<SummaryQueryModel, String> packNameCol;
    @FXML
    private TableColumn<SummaryQueryModel, Integer> boxNumCol;
    @FXML
    private TableColumn<SummaryQueryModel, Integer> canNumCol;
    @FXML
    private TableColumn<SummaryQueryModel, BigDecimal> netWeightCol;
    @FXML
    private TableView<SummaryQueryModel> tableView;

    @FXML
    public void initialize() {

        // 设置列的单元格值工厂
        snCol.setCellValueFactory(new PropertyValueFactory<>("sn"));
        produceNameCol.setCellValueFactory(new PropertyValueFactory<>("produceName"));
        produceSpecCol.setCellValueFactory(new PropertyValueFactory<>("produceSpec"));
        batchNumCol.setCellValueFactory(new PropertyValueFactory<>("batchNum"));
        gradeCol.setCellValueFactory(new PropertyValueFactory<>("grade"));
        sizeCol.setCellValueFactory(new PropertyValueFactory<>("size"));
        packNameCol.setCellValueFactory(new PropertyValueFactory<>("packName"));
        boxNumCol.setCellValueFactory(new PropertyValueFactory<>("boxNum"));
        canNumCol.setCellValueFactory(new PropertyValueFactory<>("canNum"));
        netWeightCol.setCellValueFactory(new PropertyValueFactory<>("netWeight"));

        SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

        // 创建数据并填充表格
        ObservableList<SummaryQueryModel> data = FXCollections.observableArrayList(new SummaryQueryModel(1L,"班次1",
                "D1", "大包裝",3,
                "品名111","規格222","批號",
                "等级A",BigDecimal.valueOf(1.22),3,4,BigDecimal.valueOf(6.66),new Date(), dayFormat.format(new Date()), timeFormat.format(new Date())));
        tableView.setItems(data);

    }

}
